/**
 * Created by apple on 16/3/31.
 */
class Controller {
    constructor (ApiService, uiNotification, $modalInstance, $cookies, items) {
        "ngInject"
        this.uiModal = $modalInstance;
        this.service = ApiService;
        this.notify  = uiNotification;
        // this.ctgUser = $cookies.get('ctgUser') && JSON.parse($cookies.get('ctgUser'));
        this.ctgUser = items;
        this.data    = {
            'sysUserId': this.ctgUser.sysUserId
        };
    }

    checkValid (field) {
        if ( field.$pristine ) {
            field.$pristine = false;
        }
    }

    save () {
        if ( this.submitting ) return;
        this.submitting = true;
        this.service.updatePassword(this.data).then(() => {
            this.uiModal.close(this.data);
            this.notify.success({
                'title'  : '提示',
                'message': '操作成功!'
            });
        }).catch((data) => {
            this.notify.error({
                'title'  : '提示',
                'message': '操作失败. ' + (data.resultMsg ? data.resultMsg : '')
            });
        }).finally(() => {
            // 隐藏 loading
            this.submitting = false;
        });
    }

    cancel () {
        this.uiModal.dismiss('cancel')
    }
}

export default Controller;